package com.smcaiot.jfttask.south.adapter;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smcaiot.jfttask.domain.Task;
import com.smcaiot.jfttask.domain.TaskId;
import com.smcaiot.jfttask.south.convert.JftTaskInfoConvert;
import com.smcaiot.jfttask.south.entity.JftTaskInfo;
import com.smcaiot.jfttask.south.mapper.JftTaskInfoMapper;
import com.smcaiot.jfttask.south.port.TaskRepository;
import org.springframework.stereotype.Component;

/**
 * @Author: cz
 * @Date: 2023/9/27
 * @Description:
 */
@Component
public class TaskRepositoryAdapter extends ServiceImpl<JftTaskInfoMapper, JftTaskInfo> implements TaskRepository {
    @Override
    public void saveTask(Task task) {
        task.setTaskId(TaskId.next());
        JftTaskInfo taskInfo = JftTaskInfoConvert.INSTANCE.from(task);
        save(taskInfo);
    }

    @Override
    public void deleteByTaskId(TaskId taskId) {
        getBaseMapper().deleteByTaskId(taskId.value());
    }

    @Override
    public Task findByTaskId(TaskId taskId) {
        JftTaskInfo taskInfo = getBaseMapper().findByTaskId(taskId.value());
        return JftTaskInfoConvert.INSTANCE.to(taskInfo);
    }
}
